<?php

/*********************************

	@author		Chris Hazekamp
	@copyright	2010 Adena Internet
	@site		Vrijwilligers Vacatures
	
	@file		class.ftp.php
	@date		26-03-2010 15:56
	@access		internal

***********************************/

if (!defined('PUBLIC_HTML'))
{
	exit;
}

class WebFTP
{
	private $ftp_host;
	private $ftp_user;
	private $ftp_server;
	private $ftp_pass;
	private $ftp_port;
	
	public function __constructor($ftp_host, $ftp_server, $ftp_user, $ftp_pass, $ftp_port='21')
	{
		try 
		{
			$this->connect = ftp_connect($ftp_server, $ftp_port);
			
			try
			{
				$this->login = ftp_login($this->connect, $ftp_user, $ftp_pass);
			}
			catch (Exception $e)
			{
				throw new Exception('FTP Error: '.$e->getMessage());
			}
		}
		catch (Exception $e)
		{
			throw new Exception('FTP Error: '.$e->getMessage());
		}
	}
	
	public function set_dir($new_dir)
	{
		try
		{
			$ftp_set_dir = ftp_chdir($this->connect, $new_dir);
		}
		catch (Exception $e)
		{
			throw new Exception('FTP Error: '.$e->getMessage());
		}
	}
	
	public function download($remote_file, $local_file)
	{
		try
		{
			$ftp_download = ftp_get($this->connect, $local_file, $remote_file, FTP_BINARY);
		}
		catch (Exception $e)
		{
			throw new Exception('FTP Error: '.$e->getMessage());
		}
	}
	
	public function upload($local_file, $new_file)
	{
		try
		{
			$ftp_upload = ftp_put($this->connect, $new_file, $local_file);
		}
		catch(Exception $e)
		{
			throw new Exception('FTP Error: '.$e->getMessage());
		}
	}
	
	public function delete($file)
	{
		try
		{
			$ftp_delete = ftp_delete($this->connect, $file);
		}
		catch (Excepttion $e)
		{
			throw new Exception('FTP Error: '.$e->getMessage());
		}
	}
	
	public function __destructor()
	{
		ftp_close($this->connect);
		unset($this->connect);
	}
}
?>